
/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) :
        val(x), next(NULL) {
    }
};
*/
#include <unordered_map>
class Solution {
public:
    ListNode* EntryNodeOfLoop(ListNode* pHead) {
        std::unordered_map<ListNode*, int> ps;
        while (pHead)
        {
            ps[pHead]++;
            pHead = pHead->next;
            if (ps[pHead] == 2)
            {
                return pHead;
            }
        }
        return nullptr;
    }
};